package cn_dk;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Auther:dingkai
 * @date:2021/11/30 0030 下午 6:36
 * @Desc:
 */
@WebServlet(urlPatterns = "/ResponseServlet")
public class ResponseServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置响应体及响应乱码
        response.setContentType("text/html;charset=utf-8");
        // 响应给浏览器
       /* PrintWriter writer = response.getWriter();
        writer.println("<h2>servlet是动态网页技术</h2>");
        writer.println("<font style='color:red'>servlet</font>");
        response.getWriter().println("我是从后台响应给浏览器的");*/
       response.getWriter().println("对不起，访问的资源不在,3s后跳到别的界面");
       response.setHeader("refresh","3,url=https://www.baidu.com");

    }
}
